
use "$data/clean/clean_main_complete.dta" , replace


gen treat_pooled=control==0

tempfile main
save `main', replace

clear all
eststo clear
estimates drop _all

loc columns = 4

set obs 10
gen x = 1
gen y = 1

forval i = 1/`columns' {
	eststo col`i': reg x y
} 

loc count = 1

loc statnames ""
loc varlabels ""

/* Custom fill cells */



use `main', clear



gen pana=.
gen panb=.
gen panc=.
gen pand=.
gen pane=.
gen intt= .
gen empt =. 
gen part_aff = .

label var pana "\underline{Individual level characteristics} " 
label var panb "\underline{Prior experience} " 

label var empt " "
  
  foreach yvar of varlist pana  female age party_member member_years voice_prior   z_votes_own z_votes_other_1 z_votes_other_2 ///
 empt panb d_experience_campaign pre_doortodoor pre_days_doortodoor pre_posters pre_booth pre_online pre_call pre_friends pre_others  empt  {
	qui sum `yvar', d
	if `r(N)'!=0 {
	qui sum `yvar' if  control ==1
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col1
	
	qui sum `yvar' if control == 0
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col2
	
	
	reg `yvar'  treat_pooled, r
	local temp= _b[treat_pooled]
	cap: estadd loc thisstat`count' = string(`temp', "%9.2f"): col3
	
	test treat_pooled
	cap: estadd loc thisstat`count' = string(`r(p)', "%9.2f"): col4
	



	}

	/* Row Labels */
	
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc statnames "`statnames' thisstat`count'"
	loc count = `count' + 1
}

  

/* Footnotes */

loc prehead "\begin{tabular}{l*{`columns'}{c}} \toprule"

loc postfoot "\bottomrule \end{tabular}"

esttab col* using "$output/balance_pooled_main", booktabs cells(none) nonum nogap mtitle("Control" "Treatment" "$\Delta$" "p($\Delta=0$) ") ///
 stats(`statnames', labels(`varlabels'))  prehead("`prehead'") postfoot("`postfoot'") compress wrap replace

eststo clear

** Joint significance **

reg  treat_pooled female age party_member member_years voice_prior   z_votes_own z_votes_other_1 z_votes_other_2 ///
 d_experience_campaign pre_doortodoor pre_days_doortodoor pre_posters pre_booth pre_online pre_call pre_friends pre_others , r

test female age party_member member_years voice_prior   z_votes_own z_votes_other_1 z_votes_other_2 ///
 d_experience_campaign pre_doortodoor pre_days_doortodoor pre_posters pre_booth pre_online pre_call pre_friends pre_others
